﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <include file="Public:header" />
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerToolBar.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerButton.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerFilter.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/js/ligerui.expand.js" type="text/javascript"></script> 
    
    <script type="text/javascript">
      var grid;
      var groupnamelist=<php>echo json_encode($groupList);</php>;
        $(function ()
        {
        	//$.get("__URL__/getGroupNameList",function(data){groupnamelist=jQuery.parseJSON(data);});
        	
        	 //工具栏按钮
            var toolbarOptions = {
            		 items: [
            		   <volist id="item" name="button" >
                  	       <neq name="item['name']|strtolower" value="public" >
                  	             <neq name="item['name']|strtolower" value="index" >
                  	                  <eq name="item['access']" value="1" >
                  	                      { text:"{$item['title']}",id:"{$item['name']}", click:toolbarBtnItemClick, img: "__ROOT__{$item['nodeicon']}"},
                  	                      { line: true },
                  	                  </eq>
                  	             </neq>
                  	       </neq>
                  	  </volist>
                  	{ line: true } 
               ]
            };
        	grid=$("#maingrid").ligerGrid({
                columns: [
				{ display: '编号', name: 'id', align: 'left', width: 50, minWidth: 60 },
				{ display: '标题', name: 'title', align: 'left', width: 150, minWidth: 100 },
                { display: '名称', name: 'name', align: 'left', width: 120, minWidth: 60 },
                { display: '功能', name: 'level', align: 'left', width: 100, minWidth: 60,render: function (rowdata, rowindex, value){
                	var gm1='';
                	switch(value){
                		case "1":gm1="应用";break;
                		case "2":gm1="&nbsp;&nbsp;模块";break;
                		case "3":gm1="&nbsp;&nbsp;&nbsp;&nbsp;操作";break;
                		default:gm1="";
                	}
                	
                	return gm1;
                    }
                 },
                { display: '分组', name: 'group_id', align: 'left', width: 100, minWidth: 60,render: function (rowdata, rowindex, value){
                	var gm='';
                	for(var v in groupnamelist)
                	{
                	   if(groupnamelist[v].id==value){
                		   gm=groupnamelist[v].text;
                	   }
                	}
                	return gm;
                    }
                 },
                { display: '排序号', name: 'sort', align: 'left', width: 100, minWidth: 60 },
                { display: '状态', name: 'status',width: 40,render: function (rowdata, rowindex, value){var v=getStatus(value,true);return v;}},
                { display: '界面显示', name: 'is_show',width: 50,render: function (rowdata, rowindex, value){if(value=='1'){return '<IMG SRC="__PUBLIC__/Images/thinkphp/ok.gif" WIDTH="20" HEIGHT="20" BORDER="0"/>';}}},
                { display: '界面图标', name: 'nodeicon',width: 50,render: function (rowdata, rowindex, value){if(value){return '<IMG SRC="__ROOT__/'+value+'" WIDTH="20" HEIGHT="20" BORDER="0"/>';}}},
                { display: '操作', isSort: false, width: 150,render: function (rowdata, rowindex, value){
                    var h = "";
                    if (rowdata.status=="1"){
                    	 h += "<a href='javascript:forbid(" + rowdata.id + ")'>禁用</a> ";
                    }
                    else if(rowdata.status=="-1"){
                    	h += "<a href='javascript:resume(" + rowdata.id + ")'>回收</a> ";
                    }
                    else{
                    	h += "<a href='javascript:resume(" + rowdata.id + ")'>恢复</a> ";
                    }
                    var cc='';
                	switch(rowdata.level){
                		case "1": h += "<a href='javascript: add(" + rowdata.id + ")'>新增[模块]</a> ";break;
                		case "2": h += "<a href='javascript: add(" + rowdata.id + ")'>新增[操作]</a> ";break;
                		//default:;
                	  }
                       // h += "<a href='javascript: add(" + rowdata.id + ")'>新增"+cc+"</a> ";
                        h += "<a href='javascript:edit(" + rowdata.id + ")'>编辑</a> ";
                        h += "<a href='javascript:del(" + rowdata.id + ")'>删除</a> ";
                       
                    return h;
               }}
                ], 
                url:'__URL__/treeArray',alternatingRow: false,tree: { columnName: 'title' },
                pageSize:30 ,rownumbers:true,height:'100%',checkbox:true,autoCheckChildren:false,
                autoExpandChildren:false,onafterShowData:function(){grid.collapseAll();},
                toolbar:toolbarOptions
            });
            $("#pageloading").hide();
            //搜索表单应用ligerui样式
            $("#formsearch").ligerForm({
      		   fields:[{display:"标题",name:"title",newline:false,labelWidth:100,width:220,space:30,type:"text",cssClass:"field"},
      		           {display:"名称",name:"name",newline:false,labelWidth:100,width:220,space:30,type:"text",cssClass:"field"},
      		           {display:"分组",name:"group_id",newline:false,labelWidth:100,width:220,space:30,type:"select",cssClass:"field",comboboxName: "groupid", options: {valueFieldID: "group_id",data:groupnamelist}}
      		   ],
      		   toJSON: JSON2.stringify
      	     });

            //增加搜索按钮,并创建事件
            LG.appendSearchButtons("#formsearch", grid);

        });
        

        //工具条事件
        function toolbarBtnItemClick(item) {
            switch (item.id) {
                case "add":
                	add();
                    break;
                case "addApp":
                	add(0);
                    break;
                case "edit":
                	edit();
                    break;
                case "del":
                   del();
                    break;
                case "addButtons":
                    addButtons();
                	break;
                case "sort":
                    sort();
                     break;
                default:{
                	LG.tip("此方法没有定义,联系管理员设定按钮权限!");
                }
            }
        }
        
      
        
        function add(id)
        {
        	if($.type(id)=="undefined"){
        		var selected = grid.getSelected();
        		if (!selected) { $.ligerDialog.warn('请选择行!'); return }
        		id=selected.id;
        	}
        	top.f_addTab('node_add', '新增节点信息', '__URL__/add/pid/'+id);
        }
        
       function edit(id)
        {
        	
        	if($.type(id)=="undefined"){
        		var selected = grid.getSelected();
        		if (!selected) { $.ligerDialog.warn('请选择行!'); return }
        		id=selected.id;
        		}
        	    top.f_addTab('node_edit', '修改节点信息', '__URL__/edit/id/'+id);
        }

                                 
        function del(id)
        {
        	if($.type(id)=="undefined"){
        		var selected = grid.getSelected();
        		if (!selected) { $.ligerDialog.warn('请选择行!'); return }
        		id=selected.id;
        	}
        	 $.ligerDialog.confirm('是否真的删除此记录', function (yes){
             	if(yes){
        					$.post("__URL__/del/",{"id":id},function(data){
        						grid.loadData();
        						LG.tip($.parseJSON(data).info)
        						});
            			}
               });
        }
        function sort(id)
        {
        	checkid=getSelectedIds();
        	if($.type(id)=="undefined"){
        		var selected = grid.getSelected();
        		if (!selected) { $.ligerDialog.warn('请选择行!'); return }
        		id=selected.id;
        	}
        	mydialog=$.ligerDialog.open({ url: '__URL__/sort/pid/'+id+'/sortId/'+checkid, height: 500, width: 400,
            //  	buttons: [{ text: '确定', onclick: function (item, dialog) {save(dialog); } },
            //                { text: '取消', onclick: function (item, dialog) { dialog.close(); } }],
                            isResize: true,isHidden:false
           });
        	
        }
        
        function addButtons(id)
        {
      	   	if($.type(id)=="undefined"){
    	   		var selected = grid.getSelected();
    			if (!selected) { $.ligerDialog.warn('请选择行!'); return }
    				id=selected.id;
    			}
      	  $.ligerDialog.confirm('是否一次性增加按钮:<增加><编辑><删除><查看>', function (yes){
           	if(yes){
           		$.post("__URL__/addButtons/",{"id":id}, function(data){
               	 		grid.loadData();
               	  		LG.tip($.parseJSON(data).info);
    		     });
          	}
          });
        }
        
       
        function forbid(id){
           	$.post("__URL__/forbid/",{"id":id}, function(data){
               	 	grid.loadData();
               	  LG.tip($.parseJSON(data).info);
			});
        }
        function resume(cid){
        	$.post("__URL__/resume/", {"id":cid},function(data){
                grid.loadData();
                LG.tip($.parseJSON(data).info);
			});
        }
        function save(dialog)
        {
        	var data = dialog.frame.f_save(); 
        	
        }
        function getStatus(status, imageShow) {
        	switch(status) {
        		case '0' :
        			showText = '禁用';
        			showImg = '<IMG SRC="__PUBLIC__/Images/thinkphp/locked.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="禁用">';
        			break;
        		case '2' :
        			showText = '待审';
        			showImg = '<IMG SRC="__PUBLIC__/Images/thinkphp/prected.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="待审">';
        			break;
        		case '-1' :
        			showText = '删除';
        			showImg = '<IMG SRC="__PUBLIC__/Images/thinkphp/del.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="删除">';
        			break;
        		case '1' :
        		default :
        			showText = '正常';
        			showImg = '<IMG SRC="__PUBLIC__/Images/thinkphp/ok.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="正常">';

        	}
        	return (imageShow == true) ? showImg : showText;
        }
        function getSelectedIds()
        {
        	var rows=grid.getCheckedRows();
        	if (rows.length<2) return '';
        	var checkid=[];
        	 for(var i =0;i<rows.length;i++)
             {
        		 
        		 checkid.push(rows[i].id);   
             }
        	 return (checkid.join(','));

        }

    </script>
</head>
<body style="overflow-x:hidden; padding:2px;">
<div class="l-loading" style="display:block" id="pageloading"></div>
 	<div class="l-clear"></div>
    
 	 <div id="mainsearch" style="width:98%">
    		<div class="searchtitle">
    			<span>搜索</span><img src="__PUBLIC__/lib/icons/32X32/searchtool.gif" />
        		<div class="togglebtn"></div> 
    		</div>
   			 <div class="navline" style="margin-bottom:4px; margin-top:4px;"></div>
    		<div class="searchbox">
        		<form id="formsearch" class="l-form"></form>
    		</div>
  	</div>
  	<div class="l-clear"></div>
   <div id="maingrid"></div>
  <div style="display:none;"></div>
 
</body>
</html>
